home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / tcengine.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-06-24  |  5.2 KB  |  178 lines

  1. //******************************************************************'
  2. //*                                                                *'
  3. //*                      TurboCAD for Windows                      *'
  4. //*                   Copyright (c) 1993 - 2004                    *'
  5. //*             International Microcomputer Software, Inc.         *'
  6. //*                            (IMSI)                              *'
  7. //*                      All rights reserved.                      *'
  8. //*                                                                *'
  9. //******************************************************************'
  10. #include "StdAfx.h"
  11. #include "TcEngine.h"
  12. //class CTCEngine
  13. //{
  14. const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  15.  
  16. void TcGeometryVC_Net::TcEngine::CreategxApp(void)
  17. {
  18.     if (m_gxApp == NULL)
  19.     {
  20.         HRESULT hRes = E_FAIL;
  21.         CLSID lpclsid;
  22.         IDispatch *pDisp = NULL;
  23.         CString s("IMSIGX.Application");
  24.         hRes = CLSIDFromProgID (s.AllocSysString (),&lpclsid);
  25.         m_gxApp = new XApplicationClass;
  26.     }
  27.     
  28.     
  29. }
  30.  
  31. void TcGeometryVC_Net::TcEngine::CreategxDrawing(void)
  32. {
  33.     System::Object*  missing = NULL;
  34.  
  35.     try
  36.     {
  37.         if (m_gxApp == NULL)
  38.         {
  39.             CreategxApp();
  40.         }
  41.         if (m_gxDrawing != NULL)
  42.         {
  43.             MessageBox(NULL,"Drawing is already created !", NULL, MB_OK);
  44.         }
  45.         else
  46.         {
  47.             m_gxDrawing = m_gxApp->Drawings->Add(&missing);
  48.         }
  49.     }
  50.  
  51.     catch(System::Exception* exc)
  52.     {
  53.     }
  54. }
  55. void TcGeometryVC_Net::TcEngine::CreategxView(int  hWnd)
  56. {
  57.     Object*  missing = NULL;
  58.     Object* h;
  59.     COleVariant var;
  60.     try
  61.     {
  62.         
  63.         //h = hWnd;
  64.         if (this->m_gxDrawing != NULL)
  65.         {
  66.             h = __box(hWnd);
  67.             this->m_gxView = this->m_gxDrawing->Views->Add(&h, &missing);
  68. //            this->m_gxView = this->m_gxDrawing->Views->Add(__box(&hWnd), &missing);
  69.             //this->m_gxView->HWND = hWnd;
  70.             this->m_gxView->Update = false;
  71.             this->m_gxView->MappingMode = 1;
  72.             this->m_gxView->FixedAspectRatio = true;
  73.         }
  74.     }
  75.     
  76.     catch(System::Exception* exc)
  77.     {
  78.         //Console.WriteLine("{0} Caught exception .", exc); 
  79.     }
  80.  
  81. }
  82. void TcGeometryVC_Net::TcEngine::Zoom(double dZoomFactor)
  83. {
  84.     if (dZoomFactor != 0)
  85.     {
  86.         try
  87.         {
  88.             this->m_gxView->Camera->Zoom (dZoomFactor);
  89.         }
  90.         catch (...)  // in case of paper space (not possible to get camera object in paperSpace) or unexpected error in model space
  91.         {
  92.             double xC = 0;    double yC = 0;
  93.             double w = 0;    double h = 0;
  94.    
  95.             //On Error GoTo Err
  96.             w = this->m_gxView->ViewWidth;
  97.             h = this->m_gxView->ViewHeight;
  98.    
  99.             xC = this->m_gxView->ViewLeft + w / 2;
  100.             yC = this->m_gxView->ViewTop - h / 2;
  101.             w = w * dZoomFactor;
  102.             h = h * dZoomFactor;
  103.             this->m_gxView->Update = false;
  104.         
  105.             this->m_gxView->ViewLeft = xC - w / 2;
  106.             this->m_gxView->ViewTop = yC + h / 2;
  107.             this->m_gxView->ViewWidth = w;
  108.             this->m_gxView->ViewHeight = h;
  109.         }
  110.     }
  111.     else
  112.     {
  113.         this->m_gxView->ZoomToExtents ();
  114.     }
  115. }
  116.  
  117. IGraphic* TcGeometryVC_Net::TcEngine::SelectGraphic(double xScreen, double yScreen)
  118. {
  119.     double xView, yView;
  120.     System::Object* missing = NULL;
  121.     System::Object* varVal;
  122.     BOOL bRes = TRUE;
  123.     System::Object* varTrue;
  124.     bool  varTmp __gc[] = new bool __gc[1];
  125.     varTmp[0] = TRUE;
  126.     varTrue = varTmp;
  127.     PickResult* gxPickResult;
  128.     PickEntry*  gxPickEntry;
  129.     IGraphic* gxvarGraphic = NULL;
  130.  
  131.     this->m_gxView->ScreenToView (xScreen, yScreen, &xView, &yView);
  132.     //gxPickResult = this->m_gxView->PickPoint (xView, yView,&missing,&missing, &missing, &missing,&missing, &missing,&missing);
  133.     gxPickResult = this->m_gxView->PickPoint(xView, yView, &varTrue ,&varTrue, &varTrue, &varTrue,&varTrue, &varTrue,&varTrue);
  134.     if (gxPickResult->Count != 0 )
  135.     {
  136.  
  137.         varVal  = 0;
  138.         gxPickEntry = gxPickResult->get_Item (&varVal);
  139.         gxvarGraphic = gxPickEntry->Graphic;
  140.     }
  141.     else
  142.     {
  143.         this->m_gxDrawing->Graphics->Unselect ();
  144.     }
  145.     return gxvarGraphic;
  146. }
  147. }
  148. IGraphic* TcGeometryVC_Net::TcEngine::AddCircleCenterAndPoint(double x1Screen, double y1Screen, double x2Screen, double y2Screen)
  149. {
  150.     double x1View, y1View, x2View, y2View, zView;
  151.     double x1World, y1World, x2World, y2World;
  152.     zView = 0;
  153.     IGraphic* grRet = NULL;
  154.                     
  155.     this->m_gxView->ScreenToView (x1Screen, y1Screen, &x1View, &y1View);
  156.     this->m_gxView->ScreenToView (x2Screen, y2Screen, &x2View, &y2View);
  157.     this->m_gxView->ViewToWorld (x1View, y1View,zView, &x1World, &y1World, &zView);
  158.     this->m_gxView->ViewToWorld (x2View, y2View, zView, &x2World, &y2World, &zView);
  159.             
  160.     grRet = this->m_gxDrawing->Graphics->AddCircleCenterAndPoint (x1World, y1World, 0, x2World, y2World, 0);
  161.     return grRet;
  162. }
  163. IGraphic* TcGeometryVC_Net::TcEngine::AddLineSingle(double x1Screen, double y1Screen, double x2Screen, double y2Screen)
  164. {
  165.     double x1View, y1View, x2View, y2View, zView;
  166.     double x1World, y1World, x2World, y2World;
  167.     zView = 0;
  168.     IGraphic* grRet = NULL;
  169.                     
  170.     this->m_gxView->ScreenToView (x1Screen, y1Screen, &x1View, &y1View);
  171.     this->m_gxView->ScreenToView (x2Screen, y2Screen, &x2View, &y2View);
  172.     this->m_gxView->ViewToWorld (x1View, y1View,zView, &x1World, &y1World, &zView);
  173.     this->m_gxView->ViewToWorld (x2View, y2View, zView, &x2World, &y2World, &zView);
  174.                     
  175.     grRet = this->m_gxDrawing->Graphics->AddLineSingle (x1World,y1World,0,x2World,y2World,0);
  176.     return grRet;
  177. }
  178.